<template>
  <div>
    <el-card shadow="always">
      <el-divider content-position="left"><span style="font-size: 18px;">发货基本信息
       <el-button @click="Colse()" size="mini" type="primary" style="margin-left: 35px">关闭</el-button>
      </span></el-divider>

      <el-form ref="form" :model="form" label-width="160px">
        <el-row>
          <el-col :span="6">
            <el-form-item>
                <span slot="label">
                  申请发货日期：<span class="redColor">*</span>
                  <el-tooltip placement="right">
                    <div slot="content">
                      申请发货日期
                    </div>
                    <i class="el-icon-question"></i>
                  </el-tooltip>
                </span>

              <el-date-picker
                v-model="form.SAN_Time"
                placeholder="选择申请发货日期"
                size="small"
                type="date"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
                :picker-options="pickerOptionsDay">
              </el-date-picker>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item>
                <span slot="label">
                  发货类型
                  <el-tooltip placement="right">
                    <div slot="content">
                      发货类型 客户发货 》 直发给客户 ，其他发货 》 其他发货类型
                    </div>
                    <i class="el-icon-question"></i>
                  </el-tooltip>
                </span>
              <template>
                <el-radio-group>
                  <label class="el-radio " v-for="(item,index) in DeliveryTypeOption">
                                    <span class="el-radio__input my_checkbox__inner">
                                    <input type="radio" v-model="form.SAN_StyID"
                                           name="IS_STOP"
                                           :value="item.dictValue"/>
                                     </span>
                    <span class="el-radio__label ">{{item.dictLabel}}</span>
                  </label>
                </el-radio-group>
              </template>
            </el-form-item>
          </el-col>

        </el-row>


        <!-- 客户查询条件 组件 -->
        <CustomerInquiries
          ref="customerInquiries"
          :CustomerOneCategoryOption="CustomerOneCategoryOption"
          :CustomerTowCategoryOption="CustomerTowCategoryOption"
          :Sel="Sel"
          :loadingSelOption="loadingSelOption"
          :CustomerGradeOption="CustomerGradeOption"
          :selFindoptions="selFindoptions"
          :setCustomerArr="setCustomerArr"

          @SetSel="SetSel"

        />

        <el-row>
          <el-col :span="8">
            <el-form-item>
                <span slot="label">
                  企业名称：
                  <el-tooltip placement="right">
                    <div slot="content">
                      合同甲方 根据上方筛选条件得到，企业名称切换时销售合同发货 订单编号不会联动显示 ，请先选择企业名称后 再次勾选上合同发货！
                    </div>
                    <i class="el-icon-question"></i>
                  </el-tooltip>
                </span>
              <el-select v-model="form.SAN_CoID" placeholder="请选择" @change="changeC_id" style="width: 350px;">
                <el-option
                  v-for="item in CustomerOption"
                  :key="item.id"
                  :label="item.c_name"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item>
                <span slot="label">
                    发货人：
                    <el-tooltip placement="right">
                      <div slot="content">
                        发货人
                      </div>
                      <i class="el-icon-question"></i>
                    </el-tooltip>
                  </span>
              <el-select v-model="form.SAN_UserID"  placeholder="发货人"
                         @change="changeParty_a">
                <el-option
                  v-for="item in HeadquartersnOrmalOption"
                  :key="item.user_id"
                  :label="item.nick_name"
                  :value="item.user_id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item>
                <span slot="label">
                    收件人：
                    <el-tooltip placement="right">
                      <div slot="content">
                        收件人
                      </div>
                      <i class="el-icon-question"></i>
                    </el-tooltip>
                  </span>
              <el-select v-model="form.c_party_a_id" v-show="!form.IsManualBool" placeholder="收件人"
                         @change="changeParty_a">
                <el-option
                  v-for="item in PeopleOption"
                  :key="item.id"
                  :label="item.NAME"
                  :value="item.id"
                />
              </el-select>
              <el-input v-model="form.Manual_SAN_Recipient_Name" v-show="form.IsManualBool" placeholder="手动填写 收件人"/>
            </el-form-item>
          </el-col>

        </el-row>

        <el-row>

          <el-col :span="6">
            <el-form-item>
                  <span slot="label">
                      收件人电话：
                      <el-tooltip placement="right">
                        <div slot="content">
                          收件人电话
                        </div>
                        <i class="el-icon-question"></i>
                      </el-tooltip>
                    </span>
              <el-input v-model="form.SAN_Recipient_Tel" v-show="!form.IsManualBool" readonly placeholder="收件人电话"/>
              <el-input v-model="form.Manual_SAN_Recipient_Tel" v-show="form.IsManualBool" placeholder="手动填写 收件人电话"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item>
                  <span slot="label">
                      收件地址：
                      <el-tooltip placement="right">
                        <div slot="content">
                          收件地址
                        </div>
                        <i class="el-icon-question"></i>
                      </el-tooltip>
                    </span>
              <el-select v-model="form.SAN_Recipient_Address" v-show="!form.IsManualBool" placeholder="收件地址"
                         style="width: 100%;">
                <el-option
                  v-for="item in AccountOption"
                  :key="item.Cat_ID"
                  :label="item.Cat_Address"
                  :value="item.Cat_Address"
                />
              </el-select>
              <el-input v-model="form.Manual_SAN_Recipient_Address" v-show="form.IsManualBool" placeholder="手动填写 收件地址"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item>
                  <span slot="label">
                      手动填写：
                      <el-tooltip placement="right">
                        <div slot="content">
                          手动填写 收件人 、电话 、 地址
                        </div>
                        <i class="el-icon-question"></i>
                      </el-tooltip>
                    </span>
              <el-switch
                v-model="form.IsManualBool"
                active-color="#13ce66"
                inactive-color="#82848a">
              </el-switch>
            </el-form-item>
          </el-col>
        </el-row>


        <el-divider content-position="left"><span style="font-size: 18px;">发货方式</span></el-divider>
        <el-row>
          <el-col :span="4">
            <el-form-item>
                  <span slot="label">
                      发货方式：
                      <el-tooltip placement="right">
                        <div slot="content">
                          发货方式 快递、物流、送货、自取、其他
                        </div>
                        <i class="el-icon-question"></i>
                      </el-tooltip>
                    </span>
              <el-select v-model="form.SAN_ShiptyID" placeholder="发货方式" @change="changeSAN_ShiptyID(null)"
                         style="width: 100%;">
                <el-option
                  v-for="dict in DeliveryMethodOption"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item>
                  <span slot="label" v-show="SAN_FpayType_show">
                      运费方式：
                      <el-tooltip placement="right">
                        <div slot="content">
                          运费方式 发货方式 为 快递、物流 时 需选择 运费方式 寄付 到付
                        </div>
                        <i class="el-icon-question"></i>
                      </el-tooltip>
                    </span>
              <el-select v-model="form.SAN_FpayType" v-show="SAN_FpayType_show" placeholder="运费方式" style="width: 100%;">
                <el-option
                  v-for="dict in ShippingMethodOption"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"

                />
              </el-select>

              <span slot="label" v-show="SAN_Delivery_Person_show">
                      送货人：
                      <el-tooltip placement="right">
                        <div slot="content">
                          送货人 发货方式 为 送货 时 需填写 送货人
                        </div>
                        <i class="el-icon-question"></i>
                      </el-tooltip>
                    </span>
              <el-input v-model="form.SAN_Delivery_Person" v-show="SAN_Delivery_Person_show" placeholder="送货人"/>

              <span slot="label" v-show="SAN_Remarks_show">
                      备注：
                      <el-tooltip placement="right">
                        <div slot="content">
                          备注 发货方式 为 自取或其他 时 需填写 备注
                        </div>
                        <i class="el-icon-question"></i>
                      </el-tooltip>
                    </span>
              <el-input type="textarea"  v-show="SAN_Remarks_show" v-model="form.SAN_Remarks"  placeholder="备注" max-length="100"/>
            </el-form-item>


          </el-col>
          <el-col :span="4">
            <el-form-item v-show="SAN_FpayType_show">
                  <span slot="label">
                      快递公司：
                      <el-tooltip placement="right">
                        <div slot="content">
                          快递公司 发货方式 为 快递、物流 时 需选择 快递公司
                        </div>
                        <i class="el-icon-question"></i>
                      </el-tooltip>
                    </span>
              <el-select v-model="form.SAN_Express_Delivery" placeholder="快递公司" style="width: 100%;">
                <el-option
                  v-for="dict in CourierCompanyOptions"
                  :key="dict.EDY_ID"
                  :label="dict.EDY_Name"
                  :value="dict.EDY_ID"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>


        <el-divider content-position="left"><span style="font-size: 18px;">发货具体信息</span></el-divider>

        <el-row>
          <el-col :span="12">
            <el-form-item>
                      <span slot="label">
                          发货来源选择：
                          <el-tooltip placement="right">
                            <div slot="content">
                              发货来源选择 合同发货（选择的客户未发货、未发全 合同）、普通发货（选择商品直接发货）、发票发货（发票信息）、其他发货（其他商品或备注等）
                              PS：新增或修改时 只会
                            </div>
                            <i class="el-icon-question"></i>
                          </el-tooltip>
                        </span>
                <el-checkbox-group v-model="form.SAN_Shipping_MethodArr" @change="ChangeSAN_Shipping_Method" style="width: 100%;">
                  <el-checkbox v-for="dict in DeliverySelectionTypeOption"
                               :disabled="tools.VerificationValIsArray(disabledDeliverySelectionType,dict.dictValue)"
                               :label="dict.dictValue" :key="dict.dictValue"  >{{dict.dictLabel}}</el-checkbox>
                </el-checkbox-group>
            </el-form-item>
         </el-col>
        </el-row>

        <el-collapse v-model="collapseSelIndex" v-show="ContractDelivery_show"  style="margin-left: 10px; margin-top: 10px;">
          <el-collapse-item name="0">
            <template slot="title" class="item_iccid">
              <div style="font-size:20px;">合同发货</div>
            </template>
            <div>
              <el-form  ref="queryForm" :inline="true" v-if="!FindOption_show" >
                <!--分类 销售合同编号-->
                <el-form-item  >
                  <span slot="label">
                          销售合同编号：
                          <el-tooltip placement="right">
                            <div slot="content">
                              销售合同编号 来源于 勾选上合同发货之前 选中的【企业】合同发货（未发货 或 未发完）的销售合同 ，
                              再次切换企业时 需在此勾选一遍合同发货！！！
                            </div>
                            <i class="el-icon-question"></i>
                          </el-tooltip>
                        </span>

                  <el-select
                    v-model="form.SAFL_ODYContractID"
                    placeholder="请选中"
                    @change="changSAFL_ODYContractID"
                    size="small"
                    style="width: 185px"
                  >
                    <el-option
                      v-for="dict in UndoneCodeOption"
                      :key="dict.ODY_Contract_ID"
                      :label="dict.ODY_Contract_ID"
                      :value="dict.ODY_Contract_ID"
                    />
                  </el-select>
                </el-form-item>
                <el-form-item>
                  <!--加载合同商品信息-->
                  <el-button @click="LoadContractShippingInformation"
                             type="success"
                             size="small"
                             plain
                  >加载合同商品信息
                  </el-button>
                </el-form-item>


              </el-form>

            </div>
            <template>
              <el-table v-loading="loading" :data="formalDetailsArr" >
                <el-table-column label="名称" align="center" prop="SAFDS_Name"/>
                <el-table-column label="合同数量" align="center" v-if="!EditBool"  prop="HT_Quantity"/>
                <el-table-column label="发货数量" align="center" v-if="EditBool"  prop="SAFDS_Sent_Quantity"/>
                <el-table-column label="合同欠发数量" align="center" prop="SAFDS_Owe_Quantity"/>
                <el-table-column label="申请发货数量" property="pricing" prop="SAFDS_ModelAndNumber">
                  <template slot-scope="scope">
                    <el-input type="number" v-model="scope.row.SAFDS_ModelAndNumber" min="1" precision="0" placeholder="申请发货数量"
                             @blur="setSAFDS_ModelAndNumber(scope.row)"  @keyup.native="tools.handleInput2"></el-input>
                  </template>
                </el-table-column>
                <el-table-column label="备注" align="center" prop="SATDS_Remarks">
                  <template slot-scope="scope">
                    <el-input type="textarea" v-model="scope.row.SAFDS_Remarks" min="1" placeholder="选填备注"
                              max-length="100"/>
                  </template>
                </el-table-column>
                <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                  <template slot-scope="scope">
                    <el-button
                      size="mini"
                      type="text"
                      icon="el-icon-delete"
                      v-if="!FindOption_show"
                      @click="DelformalDetailsArr(scope.$index,scope.row)"
                    >删除
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
            </template>
          </el-collapse-item>
        </el-collapse>

        <el-collapse v-model="collapseSelIndex" v-show="OrdinaryDelivery_show"  style="margin-left: 10px; margin-top: 10px;">
          <el-collapse-item name="1">
            <template slot="title" class="item_iccid">
              <div style="font-size:20px;">普通发货</div>
            </template>
            <div>
              <el-form  ref="queryForm" :inline="true" v-if="!FindOption_show" label-width="68px">
                <!--分类 大分类-->
                <el-form-item label="大分类" prop="status" label-width="70px">
                  <el-select
                    v-model="commodity.Cy_Sort"
                    placeholder="请选中"
                    @change="changOneClass"
                    size="small"
                    style="width: 115px"
                  >
                    <el-option
                      v-for="dict in Large_classification"
                      :key="dict.CODE"
                      :label="dict.NAME"
                      :value="dict.CODE"
                    />
                  </el-select>
                </el-form-item>
                <!--类别 小分类-->
                <el-form-item label="小分类" prop="status" label-width="70px">
                  <el-select
                    v-model="commodity.Cy_Category"
                    placeholder="请选中"
                    size="small"
                    style="width: 115px"
                  >
                    <el-option
                      v-for="dict in Small_classification"
                      :key="dict.CODE"
                      :label="dict.NAME"
                      :value="dict.CODE"
                    />
                  </el-select>
                </el-form-item>
                <el-form-item>
                  <!--加载商品-->
                  <el-button @click="LoadCommodity"
                             type="success"
                             size="small"
                             plain
                  >选择商品
                  </el-button>
                </el-form-item>
              </el-form>

            </div>
            <template>
              <el-table v-loading="loading" :data="CommodityList" >

                <el-table-column label="分类" align="center" prop="Cy_Sort">
                  <template slot-scope="scope">
                    {{tools.getkeyValue(Large_classification,scope.row.Cy_Sort,"CODE","NAME")}}
                  </template>
                </el-table-column>
                <el-table-column label="类别" align="center" prop="Cy_Category">
                  <template slot-scope="scope">
                    {{tools.getkeyValue(window['TowClass'+window['child_id_9_'+scope.row.Cy_Sort][0]],scope.row.Cy_Category,"CODE","NAME")}}
                  </template>
                </el-table-column>
                <el-table-column label="商品名称" align="center" prop="Cy_Name"/>
                <el-table-column label="编号" align="center" prop="Cy_ModelAndNumber"/>
                <el-table-column label="单位" align="center" prop="Cy_Unit"/>
                <el-table-column label="数量" property="pricing" prop="Csd_Quantity">
                  <template slot-scope="scope">
                    <el-input type="number" v-model="scope.row.Csd_Quantity" min="1" precision="0" placeholder="数量"
                             @blur="setCsd_Quantity(scope.row)" @keyup.native="tools.handleInput2"></el-input>
                  </template>
                </el-table-column>
                <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                  <template slot-scope="scope">
                    <el-button
                      size="mini"
                      type="text"
                      icon="el-icon-delete"
                      v-if="!FindOption_show"
                      @click="DelAccount(scope.$index,scope.row)"
                    >删除
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
            </template>
          </el-collapse-item>
        </el-collapse>

        <el-collapse v-model="collapseSelIndex" v-show="InvoiceDelivery_show"  style="margin-left: 10px; margin-top: 10px;">
          <el-collapse-item name="2">
            <template slot="title" class="item_iccid">
              <div style="font-size:20px;">发票发货</div>
            </template>
            <div>
              <el-form   :inline="true" v-if="!FindOption_show" label-width="68px">
                <el-form-item>
                  <!--加载商品-->
                  <el-button @click="LoadSAIE"
                             type="success"
                             size="small"
                             plain
                  >新增发票发货
                  </el-button>
                </el-form-item>
              </el-form>

            </div>
            <template>
              <el-table v-loading="loading" :data="InvoiceList" >
                <el-table-column label="开票公司" align="center" prop="SAIE_Billing_Company"/>
                <el-table-column label="数量" property="pricing" prop="SAIE_Quantity">
                  <template slot-scope="scope">
                    <el-input type="number" v-model="scope.row.SAIE_Quantity" min="1" precision="0" placeholder="数量"
                              @blur="setSAIE_Quantity(scope.row)" @keyup.native="tools.handleInput2"></el-input>
                  </template>
                </el-table-column>
                <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                  <template slot-scope="scope">
                    <el-button
                      size="mini"
                      type="text"
                      icon="el-icon-delete"
                      v-if="!FindOption_show"
                      @click="DelInvoice(scope.$index,scope.row)"
                    >删除
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
            </template>
          </el-collapse-item>
        </el-collapse>

        <el-collapse v-model="collapseSelIndex" v-show="OtherDelivery_show"  style="margin-left: 10px; margin-top: 10px;">
          <el-collapse-item name="3">
            <template slot="title" class="item_iccid">
              <div style="font-size:20px;">其他发货</div>
            </template>
            <div>
              <el-form   :inline="true"  label-width="68px">
                <el-form-item>
                  <!--加载商品-->
                  <el-button @click="LoadSAOR"
                             type="success"
                             size="small"
                             plain
                  >新增其他发货
                  </el-button>
                </el-form-item>
              </el-form>
            </div>
            <template>
              <el-table v-loading="loading" :data="otherList" >
                <el-table-column label="名称" align="center" prop="SAOR_Name"/>
                <el-table-column label="型号" align="center" prop="SAOR_ModelAndNumber"/>
                <el-table-column label="单位" align="center" prop="SAOR_Unit"/>
                <el-table-column label="数量" property="pricing" prop="SAOR_Quantity">
                  <template slot-scope="scope">
                    <el-input type="number" v-model="scope.row.SAOR_Quantity" min="1" precision="0" placeholder="数量"
                              @blur="setSAOR_Quantity(scope.row)" @keyup.native="tools.handleInput2"></el-input>
                  </template>
                </el-table-column>
                <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                  <template slot-scope="scope">
                    <el-button
                      size="mini"
                      type="text"
                      icon="el-icon-delete"
                      @click="DelOther(scope.$index,scope.row)"
                    >删除
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
            </template>
          </el-collapse-item>
        </el-collapse>

      </el-form>

    </el-card>
    <div style="float: right; margin-right: 50px;margin-top: 50px;">
      <el-button v-if="CustomerAdd" v-hasPermi="['yunze:FhglOrderDelivery:add']" type="primary" @click="Add">新 增
      </el-button>
      <el-button v-if="CustomerEdie" v-hasPermi="['yunze:FhglOrderDelivery:upd']" type="primary" @click="Edie">保 存
      </el-button>
    </div>



    <!--  新增 发票发货  信息 -->
    <el-dialog :title="Invoicetitle" :visible.sync="Invoice_show" width="960px" append-to-body>
      <el-form ref="form" :model="Invoiceform"  label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="开票公司" >
              <el-input v-model="Invoiceform.SAIE_Billing_Company" placeholder="开票公司" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="数量" >
              <el-input type="number" v-model="Invoiceform.SAIE_Quantity" min="1" precision="0" placeholder="数量"
                        @keyup.native="tools.handleInput2"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button  v-if="addInvoiceBtn"  type="primary" @click="addInvoicePush()">新增</el-button>
        <el-button  v-if="editInvoiceBtn"  type="primary" @click="Invoice_show=false">关闭</el-button>
      </div>
    </el-dialog>



    <!--  新增 其他发货  信息 -->
    <el-dialog :title="othertitle" :visible.sync="other_show" width="960px" append-to-body>
      <el-form ref="form" :model="otherform"  label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="名称" >
              <el-input v-model="otherform.SAOR_Name" placeholder="名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="型号" >
              <el-input v-model="otherform.SAOR_ModelAndNumber" placeholder="型号" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="单位" >
              <el-input v-model="otherform.SAOR_Unit" placeholder="单位" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="数量" >
              <el-input type="number" v-model="otherform.SAOR_Quantity" min="1" precision="0" placeholder="数量"
                        @keyup.native="tools.handleInput2"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button  v-if="addotherBtn"  type="primary" @click="addotherPush()">新增</el-button>
        <el-button  v-if="editotherBtn"  type="primary" @click="other_show=false">关闭</el-button>
      </div>
    </el-dialog>


    <!--加载入库商品 -->
    <el-drawer
      size="80%"
      :append-to-body="true"
      :visible.sync="innerDrawer">
        <el-row>
          <el-col :span="24">
              <!--商品选择组件-->
              <CommoditySelection ref="commoditySelection"
                        :checkedCities.sync="checkedCities"
                         :innerDrawer="innerDrawer"
                        :preservationadd="preservationadd"
                        :cities.sync="cities"
                        :cityOptions="cityOptions"
              />
          </el-col>
        </el-row>
    </el-drawer>


    <!--发货合同加载触发函数-->
    <span v-if="show_ds ==true && execute == false"  >
      {{loadingContract()}}
    </span>

    <!-- 编辑发货申请 触发函数-->
    <span v-if="show_ds ==true && Editexecute == false"  >
      {{SetShipmentApplication()}}
    </span>





  </div>
</template>

<script>

  import tools from "@/utils/yunze/tools";
  import { getQuantityShipped,findContractData,findData} from "@/api/yunze/FHGL/FhglShippingApplication";
  import { Commodity,Queryloading} from "@/api/yunze/warehouse/Inout";
  import { getUndoneContract} from "@/api/yunze/FHGL/OrderDelivery/OrderDelivery";
  import {findCustomerArr, fnidAccountArr, fnidPeopleArr} from "@/api/yunze/XSGL/customer/customer";
  import CommoditySelection from '../../common/CommoditySelection';//商品选择 组件
  import CustomerInquiries from '../../common/CustomerInquiries';//客户筛选条件 组件



  export default {
    components:{//挂载
      CommoditySelection,
      CustomerInquiries,
    },
    /*获取传值
    * 官方文档
    * https://cn.vuejs.org/v2/guide/components-props.html#%E4%BC%A0%E5%85%A5%E4%B8%80%E4%B8%AA%E5%AF%B9%E8%B1%A1%E7%9A%84%E6%89%80%E6%9C%89-property
    * String Number Boolean Array Object Date Function Symbol
    * */
    props: {//参数 接受
      CustomerOneCategoryOption: Array,// 客户一级分类
      CustomerTowCategoryOption: Array, // 客户二级分类
      Large_classification: Array,// 大分类
      Small_classification: Array,// 小分类
      DeliveryTypeOption: Array, //数据字典 发货类型
      DeliverySelectionTypeOption: Array, //数据字典 发货选择类型
      DeliveryMethodOption: Array, //数据字典 发货方式
      ShippingMethodOption: Array,//数据字典 运费方式
      contractNatureOption: Array,  //数据字典 订单合同发货信息 合同性质
      firmAccountOption: Array, //数据字典 销售单位信息
      CourierCompanyOptions: Array,//数据字典 快递公司信息
      CustomerGradeOption: Array,// 客户级别
      selFindoptions: Array,//是省市区三级联动数据（带“全部”选项）
      form: Object,// 表单参数
      getTowClass: Function,//获取二级分类
      commodity:Object,// 商品选择大小分类查询 Map
      window:Window,//window 操作对象
      CustomerAdd: Boolean, //新增 按钮
      CustomerEdie: Boolean, //编辑 按钮
      HeadquartersnOrmalOption:Array,// 总部门所有人
      SubAdd: Function,//新增 提交
      loadingSelOption: Boolean,//是否 加载 查询客户信息框
      show_ds: Boolean,// 子窗体 载入显示 bool 用来控制 当前界面触发函数
      execute:Boolean,//加载是否 已执行
      Editexecute:Boolean,//编辑时加载是否 已执行
      SubUpd: Function,//编辑 提交
      OperationType: String,//子界面执行函数 名称判断
    },
    data() {//数据变量定义
      return {
        IsLoadShooingAdd:false,// 界面是否 渲染过
        disabledDeliverySelectionType:[],//禁止选择 发货来源选择

        EditBool:false,//当前打开方式是否为 编辑
        otherList:[],//其他发货 arr
        otherList_delArr:[],//其他发货 arr 删除
        othertitle:'',//新增 发票发货 标题
        other_show:false,//新增 其他发货 显示
        addotherBtn:false,//新增按钮 其他发货 显示
        editotherBtn:false,//关闭按钮 其他发货 显示
        //其他发货 form
        otherform:{
          SAOR_Name:'',
          SAOR_ModelAndNumber:'',
          SAOR_Unit:'',
          SAOR_Quantity:'1',
        },

        InvoiceList:[],//发票发货 arr
        InvoiceList_delArr:[],//发票发货 arr 删除
        Invoicetitle:'',//新增 发票发货 标题
        Invoice_show:false,//新增 发票发货 显示
        addInvoiceBtn:false,//新增按钮 发票发货 显示
        editInvoiceBtn:false,//关闭按钮 发票发货 显示

        //发票发货 form
        Invoiceform:{
          SAIE_Billing_Company:'',
          SAIE_Quantity:'1',
        },

        SAIE_show: false,// 新增发票发货 显示
        formalDetailsArr: [],// 正式合同发货信息详情
        formalDetailsArr_delArr: [],// 正式合同发货信息详情 删除
        UndoneCodeOption:[],//未完成的 销售合同
        collapseSelIndex:['0','1','2','3'],// collapse 默认展开
        cities: [],// 复选框 数组
        cityOptions: [],//  复选框 检索临时缓存
        checkAll: false,//全选按钮 绑定值
        isIndeterminate: false,//全选按钮 是否选中
        checkedCities: [],//商品选择

        FindOption_show: false,//查询商品按钮 显示
        innerDrawer: false,//回显展示
        PeopleOption: [],//根据 查询条件加载的 客户联系人
        AccountOption: [],//根据 查询条件加载的 客户地址
        CustomerOption: [],//根据 查询条件加载的销售客户信息
        //  商品 信息 数据
        CommodityList: [], //普通发货
        CommodityList_delArr :[],// 普通发货 删除
        loading: false,// 遮罩层
        ContractDelivery_show: false,//合同发货 显示
        OrdinaryDelivery_show: false,//普通发货  显示
        InvoiceDelivery_show: false,//发票发货 显示
        OtherDelivery_show: false,//其他发货 显示

        //日期时间选择
        pickerOptionsDay: {
          shortcuts: [{
            text: '今天',
            onClick(picker) {
              picker.$emit('pick', tools.gitData());
            }
          }, {
            text: '昨天',
            onClick(picker) {
              picker.$emit('pick', tools.getBeforeDate(1));
            }
          }, {
            text: '一周前',
            onClick(picker) {
              picker.$emit('pick', tools.getBeforeDate(7));
            }
          }]
        },
        //当前查询参数
        Sel: {
          gradeIdArr: [],
          oneIdArr: [],
          TowIdArr: [],
          sourceIdArr: [],
          province: null,
          city: null,
          district: null,
          c_name: null,
        },
        SAN_FpayType_show: true,//运费方式 显示
        SAN_Delivery_Person_show: false,//送货人 显示
        SAN_Remarks_show: false,//备注 显示

        tools:tools,//tools 工具类


        // 查询参数
        queryParams: {},
      };
    },
    mounted() {//全部渲染完成后自动引函数 【作为子组件 该界面只会被渲染一次 显示时渲染】
        //记录 当前界面是否已经加载过一次 用来 选中 该界面 子组件赋值 【子组件在为渲染时 去设置子组件值是无法操作的】
        this.IsLoadShooingAdd = true;
        window['IsLoadShooingAdd'] = true;
        //console.log("window['IsLoadShooingAdd'] " +window['IsLoadShooingAdd'])
      },
    methods: {//函数定义

      //详情加载
      loadFindData(){

        //加载所有大分类下的小分类 避免 数据遍历时获取数据加载出错
        for (let i = 0; i < this.Large_classification.length; i++) {
          this.changOneClass(this.Large_classification[i].CODE);
        }
        //发货方式 面板 隐藏
        this.ContractDelivery_show = false;
        this.OrdinaryDelivery_show = false;
        this.InvoiceDelivery_show = false;
        this.OtherDelivery_show = false;

        let map ={};
        map.SAN_ID = this.form.SAN_ID;
        let Pwd_Str = tools.encrypt(JSON.stringify(map));
        findData(Pwd_Str).then(response => {
          let jsonobj =  JSON.parse(tools.Decrypt(response));
          //console.log(jsonobj)
          var Rmap = jsonobj.Data.SAN_Map;
          var SAN_Map = JSON.parse(JSON.stringify(this.form));
          SAN_Map.IsManual = Rmap.IsManual;
          SAN_Map.SAN_CoID = ''+Rmap.SAN_CoID;
          SAN_Map.SAN_CoName = Rmap.SAN_CoName;
          SAN_Map.SAN_Delivery_Status = ''+Rmap.SAN_Delivery_Status;
          SAN_Map.SAN_Express_Delivery = Rmap.SAN_Express_Delivery;
          SAN_Map.SAN_FpayType = ''+Rmap.SAN_FpayType;
          SAN_Map.SAN_ID = Rmap.SAN_ID;
          SAN_Map.SAN_Recipient_Address = Rmap.SAN_Recipient_Address;
          SAN_Map.SAN_Recipient_Name = Rmap.SAN_Recipient_Name;
          SAN_Map.SAN_Recipient_Tel = Rmap.SAN_Recipient_Tel;
          SAN_Map.SAN_Sender_Name = Rmap.SAN_Sender_Name;
          SAN_Map.SAN_Shipping_Method = Rmap.SAN_Shipping_Method;
          SAN_Map.SAN_Shipping_MethodArr = Rmap.SAN_Shipping_MethodArr;
          SAN_Map.SAN_ShiptyID = ''+Rmap.SAN_ShiptyID;
          SAN_Map.SAN_StyID = ''+Rmap.SAN_StyID;
          SAN_Map.SAN_Time = Rmap.SAN_Time;
          SAN_Map.SAN_UserID = Number(Rmap.SAN_UserID);
          SAN_Map.SAN_Delivery_Person = Rmap.SAN_Delivery_Person;
          SAN_Map.SAN_Tracking_Number = Rmap.SAN_Tracking_Number;
          SAN_Map.SAN_Remarks = Rmap.SAN_Remarks;
          SAN_Map.SAN_upd_Time = Rmap.SAN_upd_Time;

          SAN_Map.c_party_a_id = Rmap.c_party_a_id;

            jsonobj.Data.SAN_Map;
          let SelMap = {};//默认选中
          //手动填写是否 选中
          if(SAN_Map.IsManual=='1'){
            SAN_Map.IsManualBool = true;
            SAN_Map.Manual_SAN_Recipient_Address = SAN_Map.SAN_Recipient_Address;//手动填写 地址
            SAN_Map.Manual_SAN_Recipient_Tel = SAN_Map.SAN_Recipient_Tel;//手动填写 收件人电话
            SAN_Map.Manual_SAN_Recipient_Name = SAN_Map.SAN_Recipient_Name;//手动填写 收件人
            //原有数据 清空
            SAN_Map.SAN_Recipient_Address = null;
            SAN_Map.SAN_Recipient_Tel = null;
            SAN_Map.SAN_Recipient_Name = null;
          }else{
            SAN_Map.IsManualBool = false;
            SelMap.Sel_c_party_a_name = SAN_Map.SAN_Recipient_Name;
            SelMap.Sel_SAN_Recipient_Address = SAN_Map.SAN_Recipient_Address;
          }
          SelMap.Sel_c_name = SAN_Map.SAN_CoName;

          var SAN_Shipping_MethodArr = SAN_Map.SAN_Shipping_Method.indexOf(',')!=-1?SAN_Map.SAN_Shipping_Method.split(","):[SAN_Map.SAN_Shipping_Method];//获取发货方式数组
          SAN_Map.SAN_Shipping_MethodArr = SAN_Shipping_MethodArr;
          this.$emit("SetObj","Setform",SAN_Map);//已加载 载入合同
          this.changeSAN_ShiptyID(SAN_Map.SAN_ShiptyID); //执行 一次 发货方式 切换  显示对应数据



          this.Sel.c_name = SAN_Map.SAN_CoName;//赋值隐藏的 搜索框查询关键字
          this.setCustomerArr(SelMap);
         // R_Map.put("SAFL_Map",  fhglShippingApplicationFormalMapper.find_data(map));
          //加载 发货来源选择 对应数据
          for (let i = 0; i < SAN_Shipping_MethodArr.length; i++) {
            switch (SAN_Shipping_MethodArr[i]) {
              case "2": //合同发货
                  this.formalDetailsArr = jsonobj.Data.SAFDS_arr;
                  let UndoneCodeOption = [];
                  let SAFL_Map = jsonobj.Data.SAFL_Map;//销售合同数组
                  UndoneCodeOption.push({"ODY_Contract_ID":SAFL_Map.SAFL_ODYContractID});
                  SAN_Map.SAFL_ODYContractID = SAFL_Map.SAFL_ODYContractID;
                  this.$emit("SetObj","Setform",SAN_Map);//已加载 载入合同
                  this.UndoneCodeOption =  UndoneCodeOption;
                  this.ContractDelivery_show =  true;//合同发货 显示
                break;
              case "3": //普通发货
                this.CommodityList = jsonobj.Data.ASOY_arr;
                this.OrdinaryDelivery_show =  true;//普通发货  显示
                break;
              case "4"://发票发货
                this.InvoiceList = jsonobj.Data.SAIE_arr;
                this.InvoiceDelivery_show =  true;//发票发货 显示
                break;
              case "5": //其他发货
                this.otherList = jsonobj.Data.SAOR_arr;
                this.OtherDelivery_show =  true;//其他发货 显示
                break;
            }
          }

        });


      },


      //set 客户信息 查询参数
      SetSel(Map){
        this.Sel = Map;
        //console.log(this.Sel)
      },


      //编辑 发货申请 信息 数据载入
      SetShipmentApplication(){
        //清空 合同发货 普通发货 发票发货 其他发货 原有数据
        this.formalDetailsArr = [];
        this.CommodityList = [];
        this.InvoiceList = [];
        this.otherList = [];
        //重置数据  搜索条件选项 一级分类 二级分类 客户级别 地址选择 关键字   选项
        this.Sel = {
            gradeIdArr: [],
            oneIdArr: [],
            TowIdArr: [],
            sourceIdArr: [],
            province: null,
            city: null,
            district: null,
            c_name: null,
        };
        //当前界面 已经渲染过 时 再去 操作 子组件属性
        if(this.IsLoadShooingAdd){
          this.$refs.customerInquiries.selectedOptions = [];//地址选项
        }

        this.EditBool = true;//当前打开为 编辑模式

        //隐藏 普通发货 发票发货 其他发货
        this.OrdinaryDelivery_show = false;
        this.InvoiceDelivery_show = false;
        this.OtherDelivery_show = false;
        let SelMap = {};
        SelMap.Sel_c_name = this.form.SAN_CoName;
        this.$emit("SetObj","SetEditexecute",true);//已加载 载入合同

        this.loadFindData() //详情加载
      },



      //载入合同 信息
      loadingContract(){
        //console.log("赋值数据");
        //清空合同发货原有数据
        this.formalDetailsArr = [];
        //隐藏 普通发货 发票发货 其他发货
        this.OrdinaryDelivery_show = false;
        this.InvoiceDelivery_show = false;
        this.OtherDelivery_show = false;

        let SelMap = {};
        SelMap.Sel_c_name = this.form.SAN_CoName;
        this.$emit("SetObj","SetExecute",true);//已加载 载入合同

        this.Sel.c_name = this.form.SAN_CoName;//赋值隐藏的 搜索框查询关键字
        //console.log(SelMap);
        this.disabledDeliverySelectionType = ['2'];//禁止再勾选 合同发货
        this.ContractDelivery_show =  true,//合同发货显示 显示
        //直接复制 合同编号 至 合同编号选择则 不再加载该客户其他合同
          this.UndoneCodeOption = [{"ODY_Contract_ID":this.form.SAFL_ODYContractID}];
        this.setCustomerArr(SelMap);
        //this.findUndoneContract();
        //加载 发货信息
        this.LoadContractShippingInformation()
      },






      //新增发票发货 按钮点击
      LoadSAIE(){
        this.Invoicetitle = '新增 发票发货';//发票发货 标题
        this.Invoice_show = true;//发票发货 显示
        this.addInvoiceBtn = true;//新增按钮 发票发货 显示
        this.editInvoiceBtn =  true,//关闭按钮 发票发货 显示


          //发票发货 form
        this.Invoiceform = {
          SAIE_Billing_Company:'',
          SAIE_Quantity:'1'
        };
      },
      //新增发票发货
      addInvoicePush(){
        let _this = this;
        if (tools.VerificationsText(_this, _this.Invoiceform.SAIE_Billing_Company, "请填写开票公司！") == true &&
          tools.VerificationsText(_this, _this.Invoiceform.SAIE_Quantity, "请选择开票数量！") == true) {
          let map = JSON.parse(JSON.stringify(this.Invoiceform));
          this.InvoiceList.push(map);
          this.msgSuccess("已添加至界面缓存，需点击确认保存！");
        }
      },

      //删除 发票发货
      DelInvoice(index, row) {
        if (row.SAIE_ID != null && row.SAIE_ID != "" ) {
          this.InvoiceList_delArr.push(row.SAIE_ID);
        }
        this.InvoiceList.splice(index, 1);
        this.msgSuccess("已删除界面缓存，需点击确认保存！");
      },

      //新增 其他发货 按钮点击
      LoadSAOR(){
        this.othertitle = '新增 发票发货';//发票发货 标题
        this.other_show = true;//发票发货 显示
        this.addotherBtn = true;//新增按钮 发票发货 显示
        this.editotherBtn =  true,//关闭按钮 发票发货 显示
          //发票发货 form
          this.otherform = {
            SAOR_Name:'',
            SAOR_ModelAndNumber:'',
            SAOR_Unit:'',
            SAOR_Quantity:'1',
          };
      },
      //新增 其他发货
      addotherPush(){
        let _this = this;
        if (tools.VerificationsText(_this, _this.otherform.SAOR_Name, "请填写名称！") == true &&
          tools.VerificationsText(_this, _this.otherform.SAOR_Unit, "请填写单位！") == true &&
          tools.VerificationsText(_this, _this.otherform.SAOR_Quantity, "请选择数量！") == true) {
          let map = JSON.parse(JSON.stringify(this.otherform));
          this.otherList.push(map);
          this.msgSuccess("已添加至界面缓存，需点击确认保存！");
        }
      },

      //删除 其他发货
      DelOther(index, row) {
        if (row.SAOR_ID != null && row.SAOR_ID != "" ) {
          this.otherList_delArr.push(row.SAOR_ID);
        }
        this.otherList.splice(index, 1);
        this.msgSuccess("已删除界面缓存，需点击确认保存！");
      },



      //查询商品已发货数量 储存到界面缓存
      getQuantitySd(Pmap){
        let Pwd_Str = tools.encrypt(JSON.stringify(Pmap));
        getQuantityShipped(Pwd_Str).then(response => {
          let jsonobj =  JSON.parse(tools.Decrypt(response));
          //console.log(jsonobj)
          var map = {};
          for (let i = 0; i < jsonobj.Data.length; i++) {
            let obj = jsonobj.Data[i];
            map[obj.Name] = obj.Sent_Quantity;
          }
          if(Pmap.type=='CT'){
            window['CT_Sent_Map'] = map;
          }else{
            window['TCT_Sent_Map'] = map;
          }
          var CT_Sent_Map = window['CT_Sent_Map'];
          //加载合同 发货信息
          findContractData(Pwd_Str).then(response => {
            let jsonobj_1 =  JSON.parse(tools.Decrypt(response));
            let XCT_Name_arr = [];//销售合同过来的 商品名称记录
            let S_Name_arr = [];// 标配商品 名称记录

            this.formalDetailsArr = [];//清空数据
            this.formalDetailsArr_delArr = [];//清空数据
            //将现在表格里面的 数据名称 放入
           /* for (let j = 0; j < this.formalDetailsArr.length; j++) {
              S_Name_arr.push(this.formalDetailsArr[j].SAFDS_Name);
            }*/
            //let formalDetailsArr = this.formalDetailsArr;// 正式合同发货信息详情
            let html = '';
            //标配商品 加载
            //console.log(jsonobj_1)
            for (let i = 0; i < jsonobj_1.Data.length; i++) {
              let o = jsonobj_1.Data[i];
              //console.log(CT_Sent_Map[o.Csd_CyName]+"    "+o.Csd_Quantity)
              let Owe_Quantity = tools.Is_null(CT_Sent_Map[o.Csd_CyName])?tools.numSub(o.Csd_Quantity,CT_Sent_Map[o.Csd_CyName]):o.Csd_Quantity;
              //存储合同 本应有的所有 商品名称
              if(Owe_Quantity>0){
                XCT_Name_arr.push(o.Csd_CyName);
              }
              //不同名数据 数组 写入，同名数量添加
              if(tools.VerificationValIsArray(S_Name_arr, o.Csd_CyName)==false){
                let Nobj = {};
                Nobj.SAFDS_Name = o.Csd_CyName;
                Nobj.HT_Quantity = o.Csd_Quantity;//合同数量
                Nobj.SAFDS_Owe_Quantity = Owe_Quantity;//申请欠发数量
                Nobj.SAFDS_ModelAndNumber = Owe_Quantity;//申请发货数量
                Nobj.SAFDS_Remarks = '';//备注
                Nobj.SAFDS_Sort = o.Csd_Sort;//分类
                this.formalDetailsArr.push(Nobj);
                S_Name_arr.push(o.Csd_CyName);
              }else{
                //同名 时 直接累加 合同数量 欠发数量 申请发货数量
                for (let j = 0; j < this.formalDetailsArr.length; j++) {
                  //console.log(o.Csd_CyName+" "+this.formalDetailsArr[j].SAFDS_Name);
                    if(o.Csd_CyName == this.formalDetailsArr[j].SAFDS_Name){
                      this.formalDetailsArr[j].HT_Quantity = tools.accAdd(o.Csd_Quantity,this.formalDetailsArr[j].HT_Quantity);
                      this.formalDetailsArr[j].SAFDS_Owe_Quantity = tools.accAdd(o.Csd_Quantity,this.formalDetailsArr[j].SAFDS_Owe_Quantity);
                      this.formalDetailsArr[j].SAFDS_ModelAndNumber = tools.accAdd(o.Csd_Quantity,this.formalDetailsArr[j].SAFDS_ModelAndNumber);
                    }
                }
              }
            }
            //console.log(XCT_Name_arr)
            //console.log(formalDetailsArr)
            window['XCT_Name_arr'] = XCT_Name_arr;//储存本次商品名称
            //this.formalDetailsArr.push(formalDetailsArr);//数据做追加
            this.msgSuccess("已加载合同商品信息！");
          });


        });
      },

      //加载 发货信息
      LoadContractShippingInformation(){
        let Pmap = {};
        Pmap.type = 'CT';
        Pmap.ODY_Contract_ID = this.form.SAFL_ODYContractID;
        Pmap.CtID = Pmap.ODY_Contract_ID;
        //console.log(Pmap)
        this.getQuantitySd(Pmap);//加载商品申请发货数量
      },


      //格式化 合同发货数量
      setSAFDS_ModelAndNumber(row){
        if(!tools.Is_null(row.SAFDS_ModelAndNumber)){
          row.SAFDS_ModelAndNumber = 1;
        }
      },

      //格式化普通发货数量
      setCsd_Quantity(row){
        if(!tools.Is_null(row.Csd_Quantity)){
          row.Csd_Quantity = 1;
        }
      },
      //格式化 发票发货数量
      setSAIE_Quantity(row){
        if(!tools.Is_null(row.SAIE_Quantity)){
          row.SAIE_Quantity = 1;
        }
      },
      //格式化 其他发货数量
      setSAOR_Quantity(row){
        if(!tools.Is_null(row.SAOR_Quantity)){
          row.SAOR_Quantity = 1;
        }
      },



      //获取 【当前查询用户】未完成的销售合同ID
      findUndoneContract(){
        //选中 客户再查询
        if(tools.Is_null(this.form.SAN_CoID)){
          let map ={};
          map.CoID = this.form.SAN_CoID;
          let Pwd_Str = tools.encrypt(JSON.stringify(map));
          getUndoneContract(Pwd_Str).then(response => {
            let jsonobj =  JSON.parse(tools.Decrypt(response));
            //console.log(jsonobj)
            this.UndoneCodeOption = jsonobj.Data;

            if(this.UndoneCodeOption!=null &&  this.UndoneCodeOption.length>0){
              this.form.SAFL_ODYContractID = this.UndoneCodeOption[0].ODY_Contract_ID;//选中 第一个
              //this.LoadContractShippingInformation();//加载 发货信息
            }else{
              tools.open(this, "当前客户，没有待发货销售合同！");
            }
          });
        }else{
          tools.open(this, "请选择 先根据检索条件查询出 客户并选择！")
        }
      },

      //切换 销售合同订单
      changSAFL_ODYContractID(){
        //this.LoadContractShippingInformation();//加载 发货信息
      },



      //商品一级分类 切换加载
      changOneClass(val){
        let child_id = window['child_id_9_'+val];
        this.getTowClass({'Cy_Sort':child_id[0],"child_id_sel":val});
      },

      //选中 当前登录用户
      /*SetAdminOption() {
        if (this.SalesOption != null && this.SalesOption.length > 0) {
          this.AdminOption = [];
          //默认选择第一个
          this.form.c_party_b_phone = this.SalesOption[0].phonenumber;
          this.form.c_party_b_id = this.SalesOption[0].user_id;
          let username = tools.getCookie("username");
          for (let i = 0; i < this.SalesOption.length; i++) {
            let Obj = this.SalesOption[i];
            this.AdminOption.push(Obj);
            window["SalesOptionPhonenumber_" + Obj.user_id] = Obj.phonenumber;
            //选中当前登录用户信息
            //console.log(username == Obj.user_name);
            if (Obj.user_name == username) {
              this.form.c_party_b_phone = Obj.phonenumber;
              this.form.c_party_b_id = Obj.user_id;
              this.form.c_userId = Obj.user_id;
            }
          }
        }
      },*/
      rowClassName({row, rowIndex}) {
        //把每一行的索引放进row
        row.index = rowIndex;
      },



      //删除 合同商品
      DelformalDetailsArr(index, row) {
        if (row.SAFDS_ID != null && row.SAFDS_ID != "" ) {
          this.formalDetailsArr_delArr.push(row.SAFDS_ID);
        }
        this.formalDetailsArr.splice(index, 1);
        this.msgSuccess("已删除界面缓存，需点击确认保存！");
      },

      //删除 商品 信息
      DelAccount(index, row) {
        if (row.ASOY_ID != null && row.ASOY_ID != "" ) {
          this.CommodityList_delArr.push(row.ASOY_ID);
        }
        this.CommodityList.splice(index, 1);
        this.msgSuccess("已删除界面缓存，需点击确认保存！");
      },

      /*获取详细信息*/
      finddata(row) {
        let map = {};
        map.id = row.id;
        map.Csd_CtID = row.code;
        let Pwd_Str = tools.encrypt(JSON.stringify(map));
        find(Pwd_Str).then(response => {
            let jsonobj = JSON.parse(tools.Decrypt(response));
            if (jsonobj.code == 200) {
              let CMap = jsonobj.Data.CMap;
              // 数据格式化
              CMap.c_party_b_id = Number(CMap.c_party_b_id);
              CMap.c_brId = ""+CMap.c_brId;
              //CMap.SAN_CoID = ""+CMap.SAN_CoID;
              CMap.c_fatId = ""+CMap.c_fatId;
              CMap.profit_sharing = ""+CMap.profit_sharing;
              this.CommodityList = jsonobj.Data.standardList;
              //赋值 查询条件为 当前 用户名 加载客户信息
              this.Sel.c_name = CMap.c_name;
              let SelMap = {};
              SelMap.Sel_c_party_a_name = CMap.c_party_a_name;
              SelMap.Sel_SAN_Recipient_Address = CMap.SAN_Recipient_Address;
              SelMap.Sel_c_name = CMap.c_name;
              this.setCustomerArr(SelMap);


              /* //根据 名称 选中
               let vleue = 'NAME';
               let key = 'id';
               let text = this.form.c_party_a_name;
               console.log(this.PeopleOption)
               for (let i = 0; i < this.PeopleOption.length(); i++) {
                 let obj = this.PeopleOption[i]
                 if(obj.key==text){
                   this.form.c_party_a_id = obj.vleue;
                   console.log(" get key "+obj.vleue)
                 }
               }*/



              this.form = CMap;
             // this.show_ds = true;
            } else {
              this.msgError(jsonobj.msg);
            }
            this.loading = false;
          }
        );
      },



      /** 确认 载入 按钮*/
      preservationadd(){
        //清空子组件选择
        this.$refs.commoditySelection.ThischeckedCities = [];
        this.$refs.commoditySelection.checkAll = false;
        this.$refs.commoditySelection.selName = '';

        let _this = this;
        let FindArr = [];///需要去数据库查询数据的
        if(this.checkedCities != null && this.checkedCities.length>0){
          let Arr = [];
          //表格中还没有数据的时候直接去查询
          if(this.CommodityList!=null && this.CommodityList.length>0){
            for (let i = 0; i < this.checkedCities.length; i++) {
              let id = this.checkedCities[i];
              let IsEx = false;
              for (let j = 0; j < this.CommodityList.length; j++) {
                let obj_j = this.CommodityList[j];
                if(id==obj_j.Cy_ID){
                  let Csd_Quantity = tools.accAdd(''+obj_j.Csd_Quantity,'1');
                  obj_j.Csd_Quantity = Csd_Quantity;//数量
                  this.CommodityList[j] = obj_j;
                  IsEx = true;
                  break;
                }
              }
              if(!IsEx){
                FindArr.push(id);
              }
            }
          }else{
            FindArr = this.checkedCities;
          }

          if(FindArr.length>0){
            let map = {};
            map.idarr = FindArr;
            map.publish_status = '1';//上下架状态
            let Pwd_Str = tools.encrypt(JSON.stringify(map));
            // console.log(Pwd_Str);
            Queryloading(Pwd_Str).then(response => {
              let jsonobj =  JSON.parse(tools.Decrypt(response));
              //console.log(jsonobj);
              if(jsonobj.code==200){
                let CommodityList = jsonobj.Data;
                let Arr = [];
                if(CommodityList.length>0){
                  for (let i = 0; i < CommodityList.length; i++) {
                    let obj = CommodityList[i];
                    let Csd_Quantity = 1;
                    obj.Csd_Quantity = Csd_Quantity;//数量
                    Arr.push(obj);
                  }
                }
                this.CommodityList.push(...JSON.parse(JSON.stringify(Arr)));
              }else{
                this.msgError(jsonobj.msg);
              }
            });
          }
          this.innerDrawer = false;
          this.loading = false;
          this.checkAll = false;//清空数据
          this.checkedCities = [];//清空数据

        }else {
          tools.open(_this,"勾选商品不能为空！");
        }
      },


      //选择商品
      LoadCommodity(){
        //清空选择
        this.FindCommodity();
      },

      //查询商品简称
      FindCommodity(){
        //console.log(this.commodity)
        let Pwd_Str = tools.encrypt(JSON.stringify(this.commodity));
        Commodity(Pwd_Str).then(response => {
          let jsonobj =  JSON.parse(tools.Decrypt(response));
          this.cities = JSON.parse(JSON.stringify(jsonobj.Data));
          this.cityOptions = JSON.parse(JSON.stringify(jsonobj.Data));
          this.innerDrawer = true;
        });

      },




      //发货方式 切换
      changeSAN_ShiptyID(SAN_ShiptyID){
         SAN_ShiptyID = SAN_ShiptyID!=null?SAN_ShiptyID:this.form.SAN_ShiptyID;
        if(SAN_ShiptyID=='1' || SAN_ShiptyID=='2'){
          this.SAN_FpayType_show = true;
          this.SAN_Remarks_show = false;
          this.SAN_Delivery_Person_show = false;
        }else if(SAN_ShiptyID=='3'){
          this.SAN_FpayType_show = false;
          this.SAN_Remarks_show = false;
          this.SAN_Delivery_Person_show = true;
        }else if(SAN_ShiptyID=='4' || SAN_ShiptyID=='5'){
          this.SAN_FpayType_show = false;
          this.SAN_Remarks_show = true;
          this.SAN_Delivery_Person_show = false;
        }
      },

     //收件人切换 联动变更 联系人电话
      changeParty_a() {
        this.form.SAN_Recipient_Tel = window["customerPeopleTelephone_" + this.form.c_party_a_id];
      },

      //企业名称 切换联动变更 收件人 、电话 地址
      changeC_id() {
        let map = {};
        map.id = this.form.SAN_CoID;
        // 清空 收件人 电话 地址 信息
        this.form.c_party_a_id = null;
        this.form.SAN_Recipient_Tel = null;
        this.form.SAN_Recipient_Address = null;
        //console.log(map)
        this.setPeopleArr(map,null); //加载联系人信息
        this.setAccountArr(map,null); //加载 地址 信息

        //如果 当前发货方式中 够选了 合同发货 重新 加载 销售合同编号 并 清空已加载的数据
        let SelArr = this.form.SAN_Shipping_MethodArr;
        if(SelArr!=null && SelArr.length>0){
          for (let i = 0; i < SelArr.length; i++) {
            if(SelArr[i]=='2'){//合同发货
              this.form.SAFL_ODYContractID = '';//清空数据
              this.findUndoneContract();
              this.formalDetailsArr = [];//清空数据
              this.formalDetailsArr_delArr = [];//清空数据
            }
          }
        }
      },


      //加载 地址信息
      setAccountArr(map,Selected) {
        let Pwd_Str = tools.encrypt(JSON.stringify(map));
        fnidAccountArr(Pwd_Str).then(response => {
          let jsonobj = JSON.parse(tools.Decrypt(response));
          // console.log(jsonobj);
          if (jsonobj.code == 200) {
            this.AccountOption = jsonobj.Data;
            if (this.AccountOption != null && this.AccountOption.length > 0) {
              //console.log(Selected)
              if(Selected!=null){
                for (let i = 0; i < this.AccountOption.length; i++) {
                  let obj = this.AccountOption[i];
                  if(obj.Cat_Address==Selected){
                    this.form.SAN_Recipient_Address = obj.Cat_Address;
                  }
                }
              }else{
                this.form.SAN_Recipient_Address = this.AccountOption[0].Cat_Address;//默认选择第一个
              }
            }
          } else {
            let msg = jsonobj.Data != null && jsonobj.Data != '' ? jsonobj.Data : jsonobj.msg;
            this.msgError(msg);
          }
        })
      },
      //发货来源选择 切换
      ChangeSAN_Shipping_Method(){
       //console.log(this.form.SAN_Shipping_MethodArr);
        let SelArr = this.form.SAN_Shipping_MethodArr;
        this.ContractDelivery_show = false;
        this.OrdinaryDelivery_show = false;
        this.InvoiceDelivery_show = false;
        this.OtherDelivery_show = false;
        if(SelArr!=null && SelArr.length>0){
          for (let i = 0; i < SelArr.length; i++) {
            if(SelArr[i]=='2'){//合同发货
              this.findUndoneContract();
              this.ContractDelivery_show = true;
            }else if(SelArr[i]=='3'){//普通发货
              this.OrdinaryDelivery_show = true;
            }else if(SelArr[i]=='4'){//发票发货
              this.InvoiceDelivery_show = true;
            }else if(SelArr[i]=='5'){//其他发货
              this.OtherDelivery_show = true;
            }
          }
        }
      },





      //获取公司信息
      setCustomerArr(SelectedMap) {
        // console.log(SelectedMap);
        if (this.Sel.gradeIdArr.length > 0 || this.Sel.oneIdArr.length > 0 || this.Sel.TowIdArr.length > 0 ||
          tools.Is_null(this.Sel.province) == true || tools.Is_null(this.Sel.city) == true || tools.Is_null(this.Sel.district) == true ||
          tools.Is_null(this.Sel.c_name) == true) {
          // 清空 收件人 电话 地址 信息
          this.form.SAN_CoID = null;
          this.form.c_party_a_id = null;
          this.form.SAN_Recipient_Tel = null;
          this.form.SAN_Recipient_Address = null;

          let Pwd_Str = tools.encrypt(JSON.stringify(this.Sel));
          findCustomerArr(Pwd_Str).then(response => {
            let jsonobj = JSON.parse(tools.Decrypt(response));
            //console.log(jsonobj);
            if (jsonobj.code == 200) {
              this.CustomerOption = jsonobj.Data;
              if (this.CustomerOption != null && this.CustomerOption.length > 0) {
                let map = {};


                let Sel_c_party_a_name = null;
                let Sel_SAN_Recipient_Address = null;
                if(SelectedMap!=null){
                  Sel_c_party_a_name = SelectedMap.Sel_c_party_a_name;
                  Sel_SAN_Recipient_Address = SelectedMap.Sel_SAN_Recipient_Address;
                  let Sel_c_name = SelectedMap.Sel_c_name;
                  for (let i = 0; i < this.CustomerOption.length; i++) {
                    let obj = this.CustomerOption[i];
                    if(Sel_c_name==obj.c_name){
                      this.form.SAN_CoID = obj.id;
                    }
                  }
                }else{
                  this.form.SAN_CoID = this.CustomerOption[0].id;//默认选择第一个  企业名称
                }
                map.id = this.form.SAN_CoID;
                this.setPeopleArr(map,Sel_c_party_a_name); //加载联系人信息
                this.setAccountArr(map,Sel_SAN_Recipient_Address); //加载 地址 信息
              }
            } else {
              let msg = jsonobj.Data != null && jsonobj.Data != '' ? jsonobj.Data : jsonobj.msg;
              this.msgError(msg);
            }
          })
        } else {
          this.msgError("请选择查询条件！");
        }
      },

      //加载联系人信息
      setPeopleArr(map,Selected) {
        let Pwd_Str = tools.encrypt(JSON.stringify(map));
        fnidPeopleArr(Pwd_Str).then(response => {
          let jsonobj = JSON.parse(tools.Decrypt(response));
          //console.log(jsonobj);
          if (jsonobj.code == 200) {
            this.PeopleOption = jsonobj.Data;
            if (this.PeopleOption != null && this.PeopleOption.length > 0) {
              let bool = false;
              //console.log(Selected)
              if(Selected==null){
                this.form.c_party_a_id = this.PeopleOption[0].id;//默认选择第一个
                this.form.SAN_Recipient_Tel = this.PeopleOption[0].telephone;//默认选择第一个
              }else{
                bool = true;
              }
              //界面储存联系人电话
              for (let i = 0; i < this.PeopleOption.length; i++) {
                window["customerPeopleTelephone_" + this.PeopleOption[i].id] = this.PeopleOption[i].telephone;
                if(bool){//有指定选中时 选中 指定的 数据
                  //console.log(this.PeopleOption[i].NAME+"    "+Selected)
                  if(this.PeopleOption[i].NAME==Selected){
                    this.form.c_party_a_id = this.PeopleOption[i].id;
                    this.form.SAN_Recipient_Tel = this.PeopleOption[i].telephone;
                  }
                }
              }
            }
          } else {
            let msg = jsonobj.Data != null && jsonobj.Data != '' ? jsonobj.Data : jsonobj.msg;
            this.msgError(msg);
          }
        })
      },



      //新增
      Add() {
        this.SubUniversalVerification(); // 提交 编辑 通用验证
      },

      // 提交 编辑 通用验证
      SubUniversalVerification(){
        //console.log(this.form);
        let _this = this;
        if (
          tools.VerificationsText(_this, _this.form.SAN_CoID, "请根据筛选条件查询并选择企业信息！") == true &&
          tools.VerificationsText(_this, _this.form.SAN_UserID, "请选择 发货人！") == true &&
          tools.VerificationsText(_this, _this.form.SAN_ShiptyID, "请选择 发货方式！") == true &&
          tools.VerificationsText(_this, _this.form.SAN_Time, "请选择 申请发货日期！") == true) {

          //发货来源必须 选择
          if(this.form.SAN_Shipping_MethodArr.length>0){

            //是否手动填写 判断  收件人 姓名。电话 地址
            if(_this.form.IsManualBool==true){
              this.form.IsManual = 1;
              if (
                tools.VerificationsText(_this, _this.form.Manual_SAN_Recipient_Address, "请填写 收件人地址信息！") == true &&
                tools.VerificationsText(_this, _this.form.Manual_SAN_Recipient_Tel, "请填写 收件人电话 ！") == true &&
                tools.VerificationsText(_this, _this.form.Manual_SAN_Recipient_Name, "请填写 收件人姓名！") == true) {

                this.ShiptyIDVerification();//发货方式验证
              }
            }else{
              this.form.IsManual = 0;
              if (
                tools.VerificationsText(_this, _this.form.SAN_Recipient_Address, "请填写 收件人地址信息！") == true &&
                tools.VerificationsText(_this, _this.form.SAN_Recipient_Tel, "请填写 收件人电话 ！") == true &&
                tools.VerificationsText(_this, _this.form.c_party_a_id, "请填写 收件人姓名！") == true) {
                this.ShiptyIDVerification();//发货方式验证
              }
            }
          }else{
            tools.open(_this, "选择发货来源！");
          }
        }
      },




      //发货方式验证
      ShiptyIDVerification(){
        let _this = this;
        let SAN_ShiptyID = this.form.SAN_ShiptyID;
        if(SAN_ShiptyID=='1' || SAN_ShiptyID=='2'){
          if (
            tools.VerificationsText(_this, _this.form.SAN_FpayType, "请选择 运费方式！") == true &&
            tools.VerificationsText(_this, _this.form.SAN_Express_Delivery, "请选择 快递公司！") == true) {
            this.ShipmentDataVerification();//发货数据验证
          }
        }else if(SAN_ShiptyID=='3'){
          if (
            tools.VerificationsText(_this, _this.form.SAN_Delivery_Person, "请填写 送货人！") == true) {
            this.ShipmentDataVerification();//发货数据验证
          }
        }else if(SAN_ShiptyID=='4' || SAN_ShiptyID=='5'){
          if (
            tools.VerificationsText(_this, _this.form.SAN_Remarks, "请填写 备注！") == true) {
            this.ShipmentDataVerification();//发货数据验证
          }
        }
      },

      //发货数据验证
      ShipmentDataVerification(){

        let Ht_bool = true,Pt_bool = true,Fp_bool = true,Qt_bool = true;
        //合同发货 判断
        if(tools.VerificationValIsArray(this.form.SAN_Shipping_MethodArr,'2')==true){
          if(this.formalDetailsArr.length>0){

          }else{
            Ht_bool = false;
            tools.open(this, "发货来源 选中 【合同发货】时需加载合同数据 或 取消勾选！");
          }
        }
        //普通发货 判断
        if(tools.VerificationValIsArray(this.form.SAN_Shipping_MethodArr,'3')==true){
          if(this.CommodityList.length>0){

          }else{
            Pt_bool = false;
            tools.open(this, "发货来源 选中 【普通发货】时需加载商品数据 或 取消勾选！");
          }
        }
        //发票发货 判断
        if(tools.VerificationValIsArray(this.form.SAN_Shipping_MethodArr,'4')==true){
          if(this.InvoiceList.length>0){

          }else{
            Fp_bool = false;
            tools.open(this, "发货来源 选中 【发票发货】时需填写发票数据 或 取消勾选！");
          }
        }
        //其他发货 判断
        if(tools.VerificationValIsArray(this.form.SAN_Shipping_MethodArr,'5')==true){
          if(this.otherList.length>0){

          }else{
            Qt_bool = false;
            tools.open(this, "发货来源 选中 【其他发货】时需填写其他数据 或 取消勾选！");
          }
        }

        if(Ht_bool == true && Pt_bool == true && Fp_bool == true && Qt_bool == true){
          //过滤申请发货 数量 为 0 的 数据 做删除
          if(this.formalDetailsArr.length>0){
            let formalDetailsArr = [];
            for (let i = 0; i < this.formalDetailsArr.length; i++) {
              let obj = this.formalDetailsArr[i];
              if(obj.SAFDS_ModelAndNumber>0){
                formalDetailsArr.push(obj);
              }
            }
            this.formalDetailsArr = formalDetailsArr;
          }
          if(this.CommodityList.length>0){
            let CommodityList = [];
            for (let i = 0; i < this.CommodityList.length; i++) {
              let obj = this.CommodityList[i];
              if(obj.Csd_Quantity>0){
                CommodityList.push(obj);
              }
            }
            this.CommodityList = CommodityList;
          }
          if(this.InvoiceList.length>0){
            let InvoiceList = [];
            for (let i = 0; i < this.InvoiceList.length; i++) {
              let obj = this.InvoiceList[i];
              if(obj.SAIE_Quantity>0){
                InvoiceList.push(obj);
              }
            }
            this.InvoiceList = InvoiceList;
          }
          if(this.otherList.length>0){
            let otherList = [];
            for (let i = 0; i < this.otherList.length; i++) {
              let obj = this.otherList[i];
              if(obj.SAOR_Quantity>0){
                otherList.push(obj);
              }
            }
            this.otherList = otherList;
          }
          if(this.formalDetailsArr.length>0 || this.CommodityList.length>0 || this.InvoiceList.length>0 || this.otherList.length>0 ){
            //数据赋值
            // 获取 SAN_CoName 客户名称  SAN_Sender_Name 发货人姓名 SAN_Recipient_Name 收件人
            this.form.SAN_CoName = tools.getkeyValue(this.CustomerOption, this.form.SAN_CoID, "id", "c_name");
            this.form.SAN_Sender_Name = tools.getkeyValue(this.HeadquartersnOrmalOption, this.form.SAN_UserID, "user_id", "nick_name");
            this.form.SAN_Recipient_Name = tools.getkeyValue(this.PeopleOption, this.form.c_party_a_id, "id", "NAME");

            let SAN_Shipping_Method = '';
            //格式化发货来源
            for (let i = 0; i <this.form.SAN_Shipping_MethodArr.length ; i++) {
              SAN_Shipping_Method += this.form.SAN_Shipping_MethodArr[i]+',';
            }
            SAN_Shipping_Method = SAN_Shipping_Method.substring(0,SAN_Shipping_Method.length-1);
            this.form.SAN_Shipping_Method = SAN_Shipping_Method;


            //提交参数打包
            let map = {};
            map.SAN_Map = this.form;
            map.SAFDS_arr = this.formalDetailsArr;
            map.ASOY_arr = this.CommodityList;
            map.SAIE_arr = this.InvoiceList;
            map.SAOR_arr = this.otherList;
            map.SAFL_Map = {"SAFL_ODYContractID":this.form.SAFL_ODYContractID};

            //判断当前操作 是编辑 还是 新增
            if(this.OperationType == 'SubAdd' ){
              var ODY_arr =[];//合同订单修改状态 数组
              //新增发货信息 中 有 销售合同 商品 时 更改 其订单合同  状态
              if(map.SAFDS_arr.length>0){
                var bool_Owe_Quantity = true;
                var Name_Count = 0;//计数 合同 商品 行数 与 现有 新增 合同行数 是否一致 \
                var SAFDS_Sent_Quantity_bool =false;//判断 是否有一 商品 欠发数量小于合同数量
                var XCT_Name_arr  = window['XCT_Name_arr'] ;// 获取 存储合同 本应有的所有 商品名称
                for (var i = 0; i < XCT_Name_arr.length; i++) {
                  var XCT_Name = XCT_Name_arr[i];
                  for (var j = 0; j < map.SAFDS_arr.length; j++) {
                    //名称 一致的商品 比较 现有 合同 欠发数量 <= 当前申请发货数量
                    if(XCT_Name==map.SAFDS_arr[j].SAFDS_Name){
                      Name_Count= tools.accAdd(1,Name_Count);
                      //只要有 条数据 商品 发了货 这个 布尔值 就为 true
                      if(SAFDS_Sent_Quantity_bool==false){
                        var SAFDS_Owe_Quantity = tools.numSub(map.SAFDS_arr[j].SAFDS_Owe_Quantity,map.SAFDS_arr[j].SAFDS_ModelAndNumber);// 合同欠发	 = 当前合同欠发 - 申请发货数量
                        SAFDS_Sent_Quantity_bool = Number(SAFDS_Owe_Quantity) < Number(map.SAFDS_arr[j].HT_Quantity);
                      }
                      //判断所有商品欠发 数量 <=  当前申请发货数量
                      if(bool_Owe_Quantity==true){
                        //console.log('map.SAFDS_arr[j].SAFDS_Owe_Quantity   - '+map.SAFDS_arr[j].SAFDS_Owe_Quantity+'  - map.SAFDS_arr[j].SAFDS_ModelAndNumber  '+map.SAFDS_arr[j].SAFDS_ModelAndNumber);
                        bool_Owe_Quantity = Number(map.SAFDS_arr[j].SAFDS_Owe_Quantity) <= Number(map.SAFDS_arr[j].SAFDS_ModelAndNumber);
                      }
                    }
                  }
                }
                //console.log('bool_Owe_Quantity  - '+bool_Owe_Quantity+'   SAFDS_Sent_Quantity_bool -  '+SAFDS_Sent_Quantity_bool)
                //console.log('XCT_Name_arr.length  - '+XCT_Name_arr.length+'   Name_Count -  '+Name_Count)
                var ODY_dsID = XCT_Name_arr.length == Name_Count && bool_Owe_Quantity ==true?3:SAFDS_Sent_Quantity_bool==true?2:1;
                ODY_arr.push({'ODY_Contract_ID':map.SAFL_Map.SAFL_ODYContractID,"ODY_dsID":ODY_dsID});
              }
              map.ODY_arr = ODY_arr;
              this.SubAdd(map);
            }else if (this.OperationType == 'SubUpd'){
              this.SubUpd(map);
            }



            //console.log(ODY_arr)
            //console.log(map)

            /*console.log(this.form)
            console.log(this.formalDetailsArr)
            console.log(this.CommodityList)
            console.log(this.InvoiceList)
            console.log(this.otherList)*/
          }else{
            tools.open(this, "您还未填写需要申请发货的信息！！！");
          }
        }
      },
      // 关闭
      Colse() {
        this.$emit("SetObj", "Setdrawer", false);//已加载
      },

      //编辑
      Edie() {
        this.SubUniversalVerification(); // 提交 编辑 通用验证
      },


    }
  };
</script>
